#!/usr/bin/env python
from __future__ import print_function
import pandas as pd
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from plotutil import PlotUtil


def plot(x, y, labels, prefix):
    p = PlotUtil()
    p.plot(plt.scatter, *(x, y))
    texts = [p.plot(plt.text, *(x[i], y[i], labels[i])) for i in range(x.shape[0])]
    p.plot_after()
    p.save('%s.pca.pdf' % prefix)


def main(args):
    df = pd.read_table(args.file, header=None)
    print(df.head(2))
    x = df[1].values
    y = df[2].values
    labels = df[0].values
    plot(x, y, labels, args.prefix)


if __name__ == '__main__':
    import argparse

    ap = argparse.ArgumentParser(description='plot pca')
    ap.add_argument('file', help='input file')
    ap.add_argument('-p', '--prefix', help='out prefix', default='1')
    args = ap.parse_args()

    main(args)
